package com.gt.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gt.common.annotation.Log;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.enums.BusinessType;
import com.gt.admin.domain.QualityModel;
import com.gt.admin.domain.vo.QualityModelVO;
import com.gt.admin.service.IQualityModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 质控方案模板controller
 */
@Api(tags = "sc-质控方案模板")
@RestController
@RequestMapping("/quality-config")
public class QualityModelController extends BaseController {
    @Autowired
    private IQualityModelService qualityModelService;

    /**
     * 查询质控方案
     */
    @ApiOperation("查询质控方案模板")
    @GetMapping
    public AjaxResult list(QualityModel qualityModel){
        LambdaQueryWrapper<QualityModel> queryWrapper = new LambdaQueryWrapper<>(qualityModel);
        List<QualityModel> list = qualityModelService.list(queryWrapper);
        return AjaxResult.success(list);
    }

    /**
     * 根据superid查询版本
     */
    @ApiOperation("根据superid查询版本")
    @GetMapping("/version/{superid}")
    public AjaxResult listVersion(@PathVariable("superid") Long superid){
        return AjaxResult.success(qualityModelService.selectVersion(superid));
    }

    /**
     * 根据superid查询质控方案模板
     */
    @ApiOperation("根据superid查询质控方案模板")
    @GetMapping("/{superid}")
    public AjaxResult listById(@PathVariable("superid") Long superid){
        return AjaxResult.success(qualityModelService.selectBySuperId(superid));
    }

    /**
     * 新增或修改质控方案，更新生效版本
     */
    @ApiOperation("新增或修改质控方案")
    @Log(title = "质控方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(@RequestBody QualityModelVO qualityModelVO){
        return toAjax(qualityModelService.updateByVersion(qualityModelVO));
    }

    /**
     * 删除质控方案
     */
    @ApiOperation("删除质控方案")
    @Log(title = "质控方案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{quaId}")
    public AjaxResult delete(@PathVariable("quaId")Long quaId){
        return toAjax(qualityModelService.deleteById(quaId));
    }
}